package com.cangxuan.blockchain.controller;

import com.alibaba.fastjson.JSON;
import com.cangxuan.blockchain.dto.CreateAccountDTO;
import com.cangxuan.blockchain.service.IBlockChainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
@RequestMapping("blockchain")
public class BlockChainController extends BaseController {

    IBlockChainService blockChainService;

    @Autowired
    public void setBlockChainService(IBlockChainService blockChainService) {
        this.blockChainService = blockChainService;
    }

    @GetMapping("getBlockChain/{userId}")
    public Object getBlockChain(@PathVariable long userId) {
        CreateAccountDTO account = blockChainService.createAccount(String.valueOf(userId),String.valueOf(userId));
        if (account==null){
            return fail(401,"获取区块链地址失败");
        }
        return JSON.toJSONString(success(account));
    }

}
